package com.haiqiu.tools.test.controller;

import com.haiqiu.tools.auth.inspect.TokenService;
import com.haiqiu.tools.captcha.entity.Captcha;
import com.haiqiu.tools.captcha.utils.ImgVerifyCode;
import com.haiqiu.tools.common.utils.HttpServletUtils;
import com.haiqiu.tools.test.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * 授权认证测试
 *
 * @author haiqiu
 * @since  2023/6/28
 */
@RestController
@RequestMapping("/auth")
public class AuthController {

    @Autowired
    private TokenService<SysUser> tokenService;

    @RequestMapping(value = "createToken")
    public String createToken() {
        SysUser sysUser = new SysUser();
        sysUser.setActive(true);
        sysUser.setAvatar("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fblog%2F202107%2F23%2F20210723210602_a25c3.thumb.1000_0.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1658821183&t=52541efb592f3918b7fa72b9b2582d5f");
        sysUser.setPassword("000000");
        sysUser.setPhone(ExcelController.RandomPhoneNumber.createMobile(0));
        sysUser.setEmail(ExcelController.RandomInfo.getRandomQQEmail());
        sysUser.setNickname(ExcelController.RandomInfo.getRandomGirlName());
        sysUser.setQq(ExcelController.RandomInfo.getRandomPhone());
        sysUser.setWechat(ExcelController.RandomInfo.getRandomPhone());
        sysUser.setSex(ExcelController.RandomInfo.getRandomAge(0,2));
        sysUser.setUsername(ExcelController.RandomInfo.getRandomGirlName());
        sysUser.setCreateTime(new Date());
        sysUser.setUpdateTime(new Date());
        sysUser.setLoginDate(new Date());
        String token = tokenService.createToken(sysUser);
        return token;
    }

    @RequestMapping(value = "getToken")
    public Object getToken(String token) {
        SysUser userDetail = tokenService.getUserDetail(token, SysUser.class);
        return userDetail;
    }
}
